<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>站点列表页</title>
</head>
<script type="text/javascript" src="/js/jquery-1.8.0.min.js"></script>
<body>
    <button onclick="add()">增加</button>
    <table id="container" border="1">

    </table>
</body>
<script>
    $(function () {
        $.getJSON("/back/host/getHosts" , function(result) {
            if(result.code != 200) {
                alert(result.msg);
            }else {
                //填充内容
                var str = '<tr><th>hostId</th><th>returnUrl</th><th>state</th> <th>email</th> <th>操作</th></tr>';
                result.data.forEach(function(host) {
                   str += '<tr>'
                           + '<td>'+host.hostId+'</td>'
                           + '<td>'+host.returnUrl+'</td>'
                           + '<td>'+host.state+'</td>'
                           + '<td>'+host.email+'</td>'
                           + '<td><a href="#" onclick="edit(\''+host.hostId+'\')">编辑</a>|<a href="#" onclick="del(\''+host.hostId+'\')">删除</a></td>'
                           + '</tr>';
                });
                $('#container').html(str);
            }
        });
    });

    function edit(hostId) {
        window.location.href = "/back/host/edit/"+hostId;
    }

    function add() {
        window.location.href = "/back/host/add";
    }

    function del(hostId) {
        $.ajax({
            url : '/back/host/deleteHost/'+hostId,
            type : 'POST',
            dataType : 'JSON',
            success : function(result) {
                console.info(result);
                window.location.href = "/back/host/hosts";
            }
        });
    }
</script>
</html>